//下方黑色提示面板

//Tips & Display Params

var tipPanel = {
	
	enable : true,
	
	_foldStatus : 1,//0:hide; 1:fold; 2:unfold

	_moveHeight : null,
	
	_tipNode : null,
	
	_background : null,
	_vLine : null,
	
	_leftLabel : null,
	_rightLabel : null,
	_tipLabel : null,
	
	_adjutant : null,
	
	Initialize : function(){
		this.enable = true;
		
		this._foldStatus = 1;
		
		var winSize = cc.director.getWinSize();
		
		this._moveHeight = winSize.height * 0.2 + 1
	
		this._tipNode = new cc.Node();
		this._tipNode.attr({x:0, y:0});
		campaignScene.battlelayer.addChild(this._tipNode, 150);
		
		this._background = new cc.Sprite(resource.white1010_png);
		this._background.attr({
			color : cc.color(0,0,0),
			scaleX : winSize.width * 0.1,
			scaleY : this._moveHeight * 2 * 0.1,
			x : winSize.width * 0.5,
			y : 0,
			opacity : 127
		});
		this._tipNode.addChild(this._background);
	
		var hLine = new cc.Sprite(resource.white1010_png);
		hLine.attr({
			x : winSize.width * 0.5,
			y : this._moveHeight - 1,
			scaleX : winSize.width * 0.9 * 0.1,
			scaleY : 4 * 0.1,
			opacity : 50
		});
		this._tipNode.addChild(hLine);
		
		this._vLine = new cc.Sprite(resource.white1010_png);
		this._vLine.attr({
			x : winSize.width * 0.3,
			y : 0,
			scaleX : 4 * 0.1,
			scaleY : winSize.height * 0.36 * 0.1,
			opacity : 50,
			visible : false
		});
		this._tipNode.addChild(this._vLine);
		
		this._leftLabel = cc.LabelTTF.create("", "simhei", 26);
		//this._leftLabel.setDimensions(cc.size(winSize.width * 0.2, winSize.height * 0.16));
		this._leftLabel.setHorizontalAlignment(cc.TEXT_ALIGNMENT_LEFT);
		this._leftLabel.attr({
			anchorX : 0,
			anchorY : 1.0,
			x : winSize.width * 0.05,
			y : winSize.height * 0.172
		})
		this._tipNode.addChild(this._leftLabel);
		
		this._rightLabel = cc.LabelTTF.create("", "simhei", 26);
		this._rightLabel.setHorizontalAlignment(cc.TEXT_ALIGNMENT_LEFT);
		this._rightLabel.attr({
			anchorX : 0,
			anchorY : 1.0,
			x : winSize.width * 0.34,
			y : winSize.height * 0.172
		})
		this._tipNode.addChild(this._rightLabel);
		
		this._tipLabel = cc.LabelTTF.create("", "simhei", 26);
		this._tipLabel.setHorizontalAlignment(cc.TEXT_ALIGNMENT_LEFT);
		this._tipLabel.attr({
			anchorX : 0,
			anchorY : 1.0,
			x : winSize.width * 0.13,
			y : winSize.height * 0.172
		})
		this._tipNode.addChild(this._tipLabel);
		
		this._adjutant = null;
		this.ShowAdjutantTip(campaign.description);
	},
	
	ShowUI : function(isFold, isClear){
		var foldstatus = isFold == true ? 1 : 2;
		if (this._foldStatus != foldstatus){
			this._tipNode.runAction(cc.moveTo(0.15, 0, (foldstatus - 1) *  this._moveHeight));
			this._foldStatus = foldstatus;
		}
		if (isClear){
			this._leftLabel.setString("");
			this._rightLabel.setString("");
			this._tipLabel.setString("");
			this._vLine.setVisible(false);
			this._RemoveAdjutant();
		}
	},
	
	HideUI : function(){
		if (this._foldStatus != 0){
			this._tipNode.runAction(cc.moveTo(0.15, 0, -this._moveHeight));
			this._foldStatus = 0;
			this._RemoveAdjutant();
		}
	},
	
	ShowTileParam : function(forceid, tileIndex){
		if (this.enable == false)
			return;
		
		if (this._foldStatus <= 0)
			this.ShowUI(true, false);
		
		this._tipLabel.setString("");
		this._vLine.setVisible(true);
		this._RemoveAdjutant();
		
		var defendIndex = forceInfo[forceid].defend_index[tileIndex];
		
		var leftText = "地块: 障碍指数: " + FormatNumber(forceInfo[forceid].pass_index[tileIndex], 3);
		leftText = leftText + "\n\n      防御指数: " + FormatNumber(defendIndex, 3) + "(" + FormatNumber((1 - GetDefendRate(defendIndex)), 3) + ")";
		
		this._leftLabel.setString(leftText);
		this._leftLabel.runAction(cc.blink(0.15, 1));
	},
	
	ShowTroopParam : function(troopid){
		if (this.enable == false)
			return;
		
		if (this._foldStatus <= 0)
			this.ShowUI(true, false);
		
		this._tipLabel.setString("");
		this._vLine.setVisible(true);
		this._RemoveAdjutant();
		
		var rightText = "部队: 类型: " + campaign.troop[troopid].type_name
		+ "  移动速度：" + FormatNumber(campaign.troop[troopid].move, 3)
		+ "  攻击范围：" + FormatNumber(campaign.troop[troopid].attack_range, 3);
		rightText = rightText + "\n\n      战力：规模×等级×士气 = " + FormatNumber(campaign.troop[troopid].strength, 3)
		+ "×" + FormatNumber(campaign.troop[troopid].level, 3)
		+ "×" + FormatNumber(campaign.troop[troopid].morale, 3)
		+ " = " + FormatNumber((campaign.troop[troopid].strength * campaign.troop[troopid].level * campaign.troop[troopid].morale), 3);
		
		this._rightLabel.setString(rightText);
		this._rightLabel.runAction(cc.blink(0.15, 1));
	},
	
	ShowTip : function(tip, divideSize){
		if (this.enable == false)
			return;
		
		divideSize = divideSize || 66;
		
		if (this._foldStatus <= 0)
			this.ShowUI(true, false);
		
		this._leftLabel.setString("");
		this._rightLabel.setString("");
		this._vLine.setVisible(false);
		this._RemoveAdjutant();

		var tipArray = SplitText(tip, divideSize);
		var tipText = tipArray[0];
		for (var idx = 1; idx < tipArray.length; idx++){
			tipText = tipText + "\n\n" + tipArray[idx];
		}
		this._tipLabel.setString(tipText);
		this._tipLabel.runAction(cc.blink(0.15, 1));
	},
	
	ShowAdjutantTip : function(tip){
		var winSize = cc.director.getWinSize();
		
		this.ShowTip(tip,58);
		
		if (this._adjutant != null)
			return;
		
		this._adjutant = new cc.Sprite(resource.adjutant_png);
		this._adjutant.attr({
			anchorX : 1.0,
			anchorY : 0,
			x : winSize.width + this._adjutant.width,
			y : 0
		});
		campaignScene.battlelayer.addChild(this._adjutant, 151);
		this._adjutant.runAction(cc.moveBy(0.15, -this._adjutant.width, 0));
	},
	
	_RemoveAdjutant : function(){
		if (this._adjutant == null)
			return;
		
		this._adjutant.runAction(cc.sequence(cc.moveBy(0.15, tipPanel._adjutant.width, 0),
				cc.removeSelf(), cc.callFunc(function(){ tipPanel._adjutant = null; })));
	}
};